<template>
  <div :class="{ black: isBlack, white: !isBlack }" class="nav" :style='{ position: (isfixed ? "fixed" : "relative") }'>
    <!-- 左边盒子 -->
    <div class="left-box">
      <img v-if="isBlack" src='@/assets/logo_white.png' class='logo' @click='to("/")' />
      <img v-else src='@/assets/logo.png' class='logo' @click='to("/")' />
      <div @click='to("/")'>首页</div>
      <div @click="to('/race')">竞赛</div>
      <div @click="to('/community')">社区</div>
      <div @click="to('/demo')">联系我们</div>
    </div>
    <!-- 右边盒子 -->
    <div class="right-box">
      <div style="cursor:pointer;" @click="to('/userCenter')">
        <el-avatar :size="40" :src="isLogin ? userInfo.avatar : null" />
      </div>
      <div class="logout" @click="logout" v-if="isLogin">
        <span v-if="isBlack" style="color:white;">退出登录</span>
        <span v-else>退出登录</span>
      </div>

      <div style="margin:0 20px 0 50px;" v-if="!isLogin" @click="to('/login')">

        <el-button plain v-if="!isBlack">登录</el-button>
        <div v-else class="black-btn">
          <div>登录</div>
        </div>
      </div>
      <div style="margin-right:20px;" v-if="!isLogin" @click="to('/register')">
        <el-button plain v-if="!isBlack">注册</el-button>
        <div v-else class="black-btn">
          <div>注册</div>
        </div>
      </div>

    </div>
  </div>
</template>

<script setup>
import { ref, toRef } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter();

const props = defineProps({
  isBlack: Boolean,
  isfixed: Boolean
})
const to = (url) => {
  router.push(url)
}
const isLogin = ref(false);
const { isBlack, isfixed } = props;
const userInfo = JSON.parse(
  localStorage.getItem('userInfo'));
if (userInfo) {
  isLogin.value = true;
}

console.log(isBlack);
const logout = () => {
  localStorage.removeItem('userInfo');
  localStorage.removeItem("accessToken")
  to('/')
}
</script>

<style scoped>
.nav {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  z-index: 10;
}

.black {
  background-color: rgba(46, 46, 46, 0.4);
  color: white;
}

.white {
  background-color: white;
  color: black;
}

.logout {
  color: rgba(65, 119, 247, 1);
  font-size: 14px;
  margin-left: 30px;
  margin-right: 40px;
  cursor: pointer;
}

.logo {
  width: 164px;
  height: 35px;
  margin: 0 10px;
  margin-top: 5px;
  position: inherit;
  cursor: pointer;

}

.left-box {
  display: flex;
  align-items: center;
}

.left-box div {
  margin: 0 20px;
  padding: 15px 0;
  cursor: pointer;
}

.right-box {
  display: flex;
  align-items: center;
}

.black-btn {
  border: 1px #fff solid;
  background-color: transparent;
  display: flex;
  color: #fff;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 32px;
  cursor: pointer;
}
</style>